<template>
    <div style="display: inline">
        <!-- <el-button :type="buttonType" icon="el-icon-plus" size="mini" @click="handleAdd" style="margin-bottom: 15px;">新增</el-button> -->
        <el-drawer :visible.sync="show" :close-on-press-escape="false" :title="`充值`"
            custom-class="employee-store-drawer" modal-append-to-body append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-position="right" label-width="130">
                <el-form-item label="名称">
                    {{ infoData.nickname }}
                </el-form-item>
                <el-form-item label="手机号">
                    {{ infoData.phone }}
                </el-form-item>
                <el-form-item label="当前余额">
                    {{ infoData.money }}
                </el-form-item>
                <el-form-item label="类型" prop="change_mode">
                    <el-radio-group v-model="form.change_mode">
                        <el-radio :label="1">增加</el-radio>
                        <el-radio :label="2">减少</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="变更数量" prop="money">
                    <ml-input :value.sync="form.money" num style="width: 200px" placeholder="请输入变更数量" />
                </el-form-item>
                <el-form-item label="更变后可提现余额">
                    {{ form.change_mode == 1 ? (((infoData.money / 1) + (form.money / 1))).toFixed(2) : (((infoData.money / 1) -
                        (form.money / 1))).toFixed(2) }}
                </el-form-item>
            </el-form>
            <div class="footer">
                <el-button @click="show = false">取 消</el-button>
                <el-button @click="handleUpdata">确 定</el-button>
            </div>
        </el-drawer>
    </div>
</template>
<script>
import MlInput from '@/components/MlInput/index.vue'

const Model = {
    user_id: null,
    change_mode: 1,	//true	int		类型 1 充值 2 扣减
    money: "",	//true	int		积分(正数)
}

export default {
    components: { MlInput },
    props: {
        buttonType: {
            type: String,
            default() {
                return 'primary'
            }
        }
    },
    data() {
        return {
            rules: {
                change_mode: [
                    { required: true, message: '请选择类型', trigger: 'blur' },
                ],
                money: [
                    { required: true, message: '请输入变更数量', trigger: 'blur' },
                ],
            },
            show: false,
            form: { ...{}, ...Model },
            infoData: {}
        }
    },
    methods: {
        handleAdd: function () {
            this.form = { ...{}, ...Model }
            this.show = true
        },
        handleEdit: function (obj) {
            this.infoData = { ...{}, ...obj }
            this.form.user_id = obj.id
            this.show = true
        },
        handleUpdata: function () {
            this.$refs.form.validate(async (valid) => {
                if (valid) {
                    let res = await this.$request({
                        url: '/admin/user.user/recharge',
                        method: 'post',
                        data: this.form
                    })
                    if (res.code == 200) {
                        this.show = false
                        this.$message.success('操作成功')
                        this.$emit('success')
                    }

                } else {
                    return false
                }
            })
        },
    }
}

</script>
<style lang="scss">
.employee-store-drawer {
    width: 600px !important;

    .el-drawer__title {
        border-top-left-radius: 10px !important;
    }

    .el-drawer__header {
        font-size: 16px !important;
        color: #333333 !important;
        font-weight: 700;
        text-align: center;
    }

    .el-drawer__body {
        border-bottom-left-radius: 10px !important;
        padding: 0 20px;
        overflow: scroll !important;
        padding-bottom: 50px;
    }

    .footer {
        position: absolute;
        width: 100%;
        bottom: 0;
        right: 0;
        height: 66px;
        opacity: 1;
        background: #fff;
        box-shadow: 0 -3px 6px 0 rgba(0, 0, 0, .04), 0 2px 4px 0 rgba(0, 0, 0, .5);
        display: flex;
        align-items: center;
        text-align: center;
        justify-content: center;
        z-index: 99;
    }

    .el-form-item {
        display: block;
        margin-right: 0;
        margin-bottom: 24px !important;
    }

    .el-form-item__label {
        width: 150px;
    }

    .el-form-item__content {
        width: calc(100% - 204px);
        display: inline-block;
    }

}
</style>